set_languages("cxxlatest")
add_cxxflags("/utf-8")

local slint_home = os.getenv("SLINT_HOME")
local slint_headers = path.join(slint_home, "include/slint")
local slint_lib = path.join(slint_home, "lib")

local ui_include_dir = path.join("$(projectdir)", "ui/include")

rule("slint")
do
  set_extensions(".slint")
  on_build_file(function(target, sourcefile, opt)
    os.mkdir(ui_include_dir)
    local filename = path.basename(sourcefile)
    local outfile = path.join(ui_include_dir, filename .. ".h")
    os.vrun("slint-compiler " .. sourcefile .. " -o " .. outfile)
  end)
end

target("temp-cpp-slint", function()
  set_kind("binary")
  add_rules("slint")
  add_files("src/**.cpp")
  add_files("ui/**.slint")
  add_includedirs(slint_headers)
  add_linkdirs(slint_lib)
  add_links("slint_cpp.dll")
  add_includedirs(ui_include_dir)
end)
